<%--
  Created by IntelliJ IDEA.
  User: 花花
  Date: 2021/6/28
  Time: 10:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path=request.getContextPath();
%>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑用户</title>
</head>
<style>
    #bigbox{
        margin: 0 auto;
        margin-top: 250px;
        padding: 20px 50px;
        background-color: #00000090;
        width: 400px;
        height: 350px;
        border-radius: 10px;
        text-align: center;
    }
    #editForm{
        margin-top: 30px;
    }
    #uname{
        margin-top: 5px;
        border: 0;
        padding: 5px 5px;
        border-bottom:1px solid white;
        background-color:#00000000;
        color:white;
    }
    #upwd{
        margin-top: 5px;
        border: 0;
        padding: 5px 5px;
        border-bottom:1px solid white;
        background-color:#00000000;
        color:white;
    }
    #age{
        margin-top: 5px;
        border: 0;
        padding: 5px 5px;
        border-bottom:1px solid white;
        background-color:#00000000;
        color:white;
    }
    #uroom{
        margin-top: 5px;
        border: 0;
        padding: 5px 5px;
        border-bottom:1px solid white;
        background-color:#00000000;
        color:white;
    }
    #usex{
        margin-top: 5px;
        border: 0;
        padding: 5px 5px;
        border-bottom:1px solid white;
        background-color:#00000000;
        color:white;
    }
    #editBtn{
        border:0;
        width:75px;
        height:25px;
        color:white;
        border-radius: 20px;
        background-image: linear-gradient(180deg, #2af598 0%, #009efd 100%);
    }
</style>
<body style="margin: 0;
    padding: 0;
    background-image: url(index.jpg);
background-repeat: no-repeat;">
    <div id="bigbox">
        <h1 style="color: white">编辑用户</h1>
        <form action="<%=path%>/edit" method="post" id="editForm">
            <input placeholder="用户名" type="text" name="uname" id="uname" value="${messageModel.object.userName}"><br>
            <input placeholder="密码" type="password" name="upwd" id="upwd"><br>
            <input placeholder="请输入你的年龄" type="text" name="age" id="age"><br>
            <input placeholder="请输入你的宿舍号" type="text" name="uroom" id="uroom" value="${messageModel.object.userRoom}"><br>
            <input placeholder="请输入你的性别" type="text" name="usex" id="usex" value="${messageModel.object.userSex}"><br>
            <span id="editmsg" style="font-size: 12px;color: red">${messageModel.msg}</span><br>
            <button type="button" id="editBtn">立即编辑</button>
        </form>
    </div>
</body>
<script type="text/javascript" src="js/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
    $("#editBtn").click(function(){
        //获取用户姓名和密码的值
        var uname = $("#uname").val();
        var upwd = $("#upwd").val();
        var age = $("#age").val();
        //判断姓名是否为空
        if(isEmpty(uname)){
            //如果姓名为空，提示用户（span标签赋值），并且return
            $("#editmsg").html("用户姓名不可为空！");
            return;
        }
        //判断密码是否为空
        if(isEmpty(upwd)){
            //如果密码为空，提示用户（span标签赋值），并且return
            $("#editmsg").html("用户密码不可为空！");
            return;
        }
        if(isEmpty(age)){
            $("#editmsg").html("用户年龄不可为空！");
            return;
        }
        //如果都不为空，则手动提交表单
        $("#editForm").submit();
    });
    function isEmpty(str){
        if(str==null || str.trim()==""){
            return true;
        }
        return false;

    }
</script>
</html>
